import re
import time
import requests
import datetime
import pandas as pd
now = datetime.datetime.now().strftime("%Y-%m-%d")+"-A股数据.xlsx"
url = "http://94.push2.eastmoney.com/api/qt/clist/get?cb=jQuery1124040399874179311124_1685159655748&pn=1&pz=10000&po=1&np=1&ut=bd1d9ddb04089700cf9c27f6f7426281&fltt=2&invt=2&wbp2u=|0|0|0|web&fid=f3&fs=m:0+t:6,m:0+t:80,m:1+t:2,m:1+t:23,m:0+t:81+s:2048&fields=f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152&_=1685159655749"
print("1:正在爬取数据...")
data = requests.get(url).text
p = re.compile(r'(\"f\d*\":.+?)[,}]')
result = p.findall(data)
print("\n2:数据爬取成功！！！")
stock = {'代码':[],'名称':[],'最新价':[],'涨跌幅%':[],'涨跌额':[],'成交量(手)':[],'成交额':[],'振幅%':[],'最高':[],'最低':[],'今开':[],'昨收':[],'量比':[],'换手率%':[],'市盈率':[],'市净率':[]}
print("\n3:数据正在导出...")
for i in range(1,len(result),31):
	stock['代码'].append(result[i+10][6:])
	stock['名称'].append(result[i+12][6:])
	stock['最新价'].append(result[i][5:])
	stock['涨跌幅%'].append(result[i+1][5:])
	stock['涨跌额'].append(result[i+2][5:])
	stock['成交量(手)'].append(result[i+3][5:])
	stock['成交额'].append(result[i+4][5:])
	stock['振幅%'].append(result[i+5][5:])
	stock['最高'].append(result[i+13][6:])
	stock['最低'].append(result[i+14][6:])
	stock['今开'].append(result[i+15][6:])
	stock['昨收'].append(result[i+16][6:])
	stock['量比'].append(result[i+8][6:])
	stock['换手率%'].append(result[i+6][5:])
	stock['市盈率'].append(result[i+7][5:])
	stock['市净率'].append(result[i+20][6:])
df = pd.DataFrame(stock)
df.to_excel(now,index=False)
print("\n4:数据导出成功！！！")
print("\n数据来源:东方财富网-行情中心-沪深京A股\n\n5秒后窗口自动关闭...")
time.sleep(5)
...
f12:代码
f14:名称
f2:最新价
# f3:涨跌幅%
f4:涨跌额
f5:成交量(手)
f6:成交额
# f7:振幅%
f15:最高
f16:最低
f17:今开
f18:昨收
f10:量比
# f8:换手率%
f9:市盈率
f23:市净率
...